﻿using Microsoft.EntityFrameworkCore;
using OnlineLearningSystem.IRepository;
using OnlineLearningSystem.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineLearningSystem.Repository
{
    public class TopicRepository : ITopicRepository
    {
        private readonly AppDbContext _context;

        public TopicRepository(AppDbContext context)
        {
            _context = context;
        }

        public void Create(Topic entity)
        {
            _context.Topics.Add(entity);
            _context.SaveChanges();
        }

        public void Delete(Topic topic)
        {
            _context.Topics.Remove(topic);
            _context.SaveChanges();
        }

        public Topic Get(Func<Topic, bool> wherelambda)
        {
            return _context.Topics.Where(wherelambda).FirstOrDefault();
        }

        public List<Topic> GetAll()
        {
            return _context.Topics.Include(o=>o.course).ToList();
        }

        public void Update(Topic user)
        {
            _context.Topics.Update(user);
            _context.SaveChanges();
        }
    }
}
